//Example of building a UI using dxui files
import logger from '../dxmodules/dxLogger.js'
import gpio from '../dxmodules/dxGpio.js'
import std from '../dxmodules/dxStd.js'
import * as os from "os";
//dw200 pin numbers (default)
const gpio_id_dw200 = 35

//Initialize gpio
let res = gpio.init()
logger.info('Initialize gpio', res)


//Apply for gpio
res = gpio.request(gpio_id_dw200)
logger.info('Apply for gpio', res)


std.setInterval(() => {
    //A high output level indicates that the relay is turned on.
    res = gpio.setValue(gpio_id_dw200, 1)
    logger.info('Output high level', res);

    //Get whether the current level is high or low.
    res = gpio.getValue(gpio_id_dw200)
    logger.info('The current level is', res);

    //Wait 3 seconds
    os.sleep(3000)

    //A low output level indicates that the relay is off.
    res = gpio.setValue(gpio_id_dw200, 0)
    logger.info('Output low level', res);

    res = gpio.getValue(gpio_id_dw200)
    logger.info('The current level is', res);
}, 3000)
